<?php
class User_model extends CI_Model{
	
	function get_user_by_phone($phone){
		$sql = "SELECT usr.*,stu.name FROM {$this->db->dbprefix}user usr left join {$this->db->dbprefix}o2o_student stu on stu.user_id=usr.id where mobile = '{$phone}' LIMIT 1";
		return $this->db->query($sql)->row_array();
	}

	function get_usre_shixun_order($uid){
		$time = strtotime(date("Y-m-d"));
		/*$sql = "SELECT o.buyer_user_id AS uid, item.order_id, item.course_id, ((item.create_on + 3600 * 24 * item.effective_time) - $time) / (3600 * 24) AS effective_day FROM {$this->db->dbprefix}shopping_order_item AS item ";
		$sql .= "LEFT JOIN {$this->db->dbprefix}shopping_orders AS o ON(o.order_id=item.order_id) ";
		$sql .= "WHERE o.buyer_user_id = '{$uid}' AND item.course_type = 5 AND (item.create_on + 3600 * 24 * item.effective_time) > $time  ORDER BY item.item_id DESC";
		return $this->db->query($sql)->result_array();*/
		$sql = "SELECT  * FROM {$this->db->dbprefix}o2o_student_item_terms where uid='{$uid}' AND lose_time > $time and data_type = 5 GROUP BY data_id";
		return $this->db->query($sql)->result_array();
	}
}
